<template>
  <div id="lap-app" v-loading="pFormLoading">
    <!--基本表单信息-->
    <el-form ref="form" label-width="100px" :model="pFormData" :rules="rules" :disabled="disabled">
      <el-form-item label="日志类型" prop="LoggerName">
        <el-input
          v-model="pFormData.LoggerName"
          :disabled="detailData!==null"
          maxlength="20"
          :autofocus="true"
        ></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="Remarks">
        <el-input type="textarea" v-model="pFormData.Remarks" :rows="5" maxlength="500"></el-input>
      </el-form-item>
      <el-form-item label="是否打开">
        <el-tag
          :type="pFormData.IsOpen === true ? 'success' : 'danger'"
        >{{pFormData.IsOpen===true?'打开':'关闭'}}</el-tag>
      </el-form-item>
    </el-form>
    <el-row class="lap-form-footer">
      <el-button
        type="primary"
        :disabled="pFormLoading"
        @click="(e)=>onSubmit(e,{close:true})"
      >提交&关闭</el-button>
    </el-row>
  </div>
</template>
<script>
/**
 * 此注释段用于标记页面可被自动注册到路由
 * auto-route
 */
export default {
  mixins: [$lap.FormView],
  name: "lap-app",
  components: {}, //引用组件
  props: ["detailData"],
  data() {
    return {
      pTitle: "日志类型", //页面标题
      pPageFunctionCode: "", //页面功能定义，例如：00100104
      //表单初始化绑定对象
      pFormData: {
        IsOpen: true,
      },
      /*表单校验规则 */
      rules: {
        LoggerName: [{ required: true, message: "请输入日志类型" }],
      },
    };
  },
  methods: {
    /**
     * 加载数据
     */
    platLoadData() {
      const that = this;
      return Promise.resolve().then((data) => {
        that.pFormData = that.detailData
          ? Object.assign({}, that.pFormData, that.detailData)
          : that.pFormData;
      });
    },
    /**
     * 提交数据
     */
    onSubmit(e, opts = {}) {
      const that = this;
      that.platFormValid("form", () => {
        return $lap
          .post("/MLogXWeb/LogHandler.ashx", {
            type: that.detailData ? "EditLogger" : "AddLogger",
            log: Base64.encode(JSON.stringify(that.pFormData)),
          })
          .then((data) => {
            that.$emit("after-submit", data, opts);
          });
      });
    },
  },
  watch: {},
};
</script>